package com.wn.sddfp.access.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    /**
     * 队列: sddfp-queue-bind
     * 交换机: sddfp-exchange-bind
     * 路由key: bind-card-message
     */
    String SDDFP_QUEUE_BIND = "sddfp-queue-bind";

    String SDDFP_EXCHANGE_BIND = "sddfp-exchange-bind";

    String BIND_CARD_ROUTEKEY = "bind-card-key";

    /**
     * 队列:    sddfp-queue-bind
     * 交换机:  sddfp-exchange-bind
     * 路由key: bind-card-message
     */
    @Bean
    public Queue queueBind(){
        return QueueBuilder.durable(SDDFP_QUEUE_BIND).build(); //创建队列
    }

    @Bean
    public DirectExchange exchangeBind(){
        return new DirectExchange(SDDFP_EXCHANGE_BIND);  //交换机
    }

    @Bean
    public Binding binding(Queue queueBind, DirectExchange exchangeBind) {
        return BindingBuilder.bind(queueBind).to(exchangeBind).with(BIND_CARD_ROUTEKEY); //队列和交换机进行绑定
    }

}